﻿using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace 并发控制
{
    public class HouseConfig : IEntityTypeConfiguration<House>
    {
        public void Configure(EntityTypeBuilder<House> builder)
        {
            builder.Property(x => x.Name).HasMaxLength(50).HasColumnType("nvarchar");

            /*
            //将Owner属性配置为并发令牌：只控制Owner属性的并发冲突
            builder.Property(x => x.Owner).HasMaxLength(50).HasColumnType("nvarchar").IsConcurrencyToken(); ;
            builder.Property(x => x.Price).IsConcurrencyToken();
            */

            //将RowVer属性配置为行版本号：控制整个实体的并发冲突=>只要实体有任何属性被修改，都会引发并发冲突
            builder.Property(x=>x.RowVer).IsRowVersion();
        }
    }
}
